import {defineStore} from "pinia";
import {WebSiteConfig} from "@/interface/types";
import piniaPersistConfig from "@/config/piniaPersist";

export const websiteStore = defineStore({
    id: 'qiyi183-blog-website',
    state: (): WebSiteConfig => ({
        title: import.meta.env.VITE_GLOB_APP_TITLE,
        shortName: import.meta.env.VITE_GLOB_APP_SHORT_NAME,
        keywords: import.meta.env.VITE_GLOB_APP_KEYWORDS,
        description: import.meta.env.VITE_GLOB_APP_DESC,
        version: import.meta.env.VITE_GLOB_APP_VERSION,
        copyright: import.meta.env.VITE_GLOB_APP_COPYRIGHT,
        logo: '',
        icon: '',
        initialized: true
    }),
    getters: {
        getWebsiteTitle: state => state.title,
        getWebsiteShortName: state => state.shortName,
        getWebsiteKeywords: state => state.keywords,
        getWebsiteDescription: state => state.description,
        getWebsiteLogo: state => state.logo,
        getWebsiteIcon: state => state.icon,
        getWebsiteVersion: state => state.version,
        getWebsiteCopyright: state => state.copyright,
        getConfigInitialized: state => state.initialized
    },
    actions: {
        setWebsiteTitle(data: any) {
            this.title = data.title;
        },
        setWebsiteShortName(data: any) {
            this.shortName = data.shortName;
        },
        setWebsiteKeywords(data: any) {
            this.keywords = data.keywords;
        },
        setWebsiteDescription(data: any) {
            this.description = data.description;
        },
        setWebsiteLogo(data: any) {
            this.logo = data.logo;
        },
        setWebsiteIcon(data: any) {
            this.icon = data.icon;
        },
        setWebsiteVersion(data: any) {
            this.version = data.version;
        },
        setWebsiteCopyright(data: any) {
            this.copyright = data.copyright;
        },
        setConfigInitialized(flag: boolean) {
            this.initialized = flag;
        }
    },
    persist: piniaPersistConfig('qiyi183-blog-website')
});
